var _n4;
var cc__decorate = __decorate;
Object.defineProperty(exports, "__esModule", {
  value: true
});
var $2DataManager = require("DataManager");
var $2UserDataManager = require("UserDataManager");
var $2ZombieMgr = require("ZombieMgr");
var $2SceneStage = require("SceneStage");
var $2KDefine = require("KDefine");
var $2MyUtils = require("MyUtils");
var $2StateComponent = require("StateComponent");
var $2PlantBase = require("PlantBase");
var cc__decorator = cc._decorator;
var ccp_ccclass = cc__decorator.ccclass;
var ccp_property = cc__decorator.property;
var def_Boss = _n4 = /* */function (_h$default) {
  babel_inherits(n, _h$default);
  var _super7 = babel_createSuper(n);
  function n() {
    var _this15;
    babel_classCallCheck(this, n);
    _this15 = _super7.apply(this, arguments);
    _this15.zombieID = 12;
    _this15.cd = 10;
    _this15.aniName = {
      dead: "2baozha",
      daiji: "daiji",
      forward: "ruchang",
      hurtForward: "ruchang2",
      hurtdaiji: "daiji",
      attackDaiji2: "daij2",
      hurtAttackDaiji2: "daij2",
      skillFire: "gongji",
      hurtSkillFire: "gongji",
      back: "houchebu",
      hurtBack: "houchebu",
      down: "ruchang2",
      hurtDown: "ruchang2",
      up: "2chuhua",
      hurtUp: "2chuhua",
      start: "ruchang",
      zhaohuan1: "zhaohuan1",
      zhaohuan2: "zhaohuan2",
      zhaohuan3: "zhaohuan3",
      zhaohuan4: "zhaohuan4",
      zhaohuan5: "zhaohuan5",
      hurtZhaohuan1: "zhaohuan1",
      hurtZhaohuan2: "zhaohuan2",
      hurtZhaohuan3: "zhaohuan3",
      hurtZhaohuan4: "zhaohuan4",
      hurtZhaohuan5: "zhaohuan5"
    };
    _this15.firePos = [0, 100, 200, 300];
    _this15.normalPos = -45;
    _this15.index = 0;
    return _this15;
  }
  babel_createClass(n, [{
    key: "onLoad",
    value: function onLoad() {
      _n4._instance = this;
      0 != $2DataManager.default.instance.level && (this.node.zIndex = $2KDefine.ZIndex.boss);
      if (1 == $2DataManager.default.instance.bossLevel) {
        this.zombieID = 1;
      } else {
        this.zombieID = 12;
      }
      this.setHp();
      this.setCD();
    }
  }, {
    key: "addBoss",
    value: function addBoss() {
      for (var _e3 = 0; _e3 < $2DataManager.default.instance.row; _e3++) {
        $2ZombieMgr.default.instance().zombieInRow[_e3].add(this);
      }
      $2ZombieMgr.default.instance().zombieSet.add(this);
    }
  }, {
    key: "setCD",
    value: function setCD() {
      switch ($2DataManager.default.instance.bossLevel) {
        case 1:
        case 2:
          this.cd = 10;
          break;
        case 3:
          this.cd = 5;
      }
    }
  }, {
    key: "setHp",
    value: function setHp() {
      switch ($2DataManager.default.instance.bossLevel) {
        case 1:
          this.allHp = 4e3 * $2UserDataManager.default.instance.chapter;
          break;
        case 2:
          this.allHp = 2e4 * $2UserDataManager.default.instance.chapter;
          break;
        case 3:
          this.allHp = 4e4 * $2UserDataManager.default.instance.chapter;
          break;
        default:
          this.allHp = 9999999;
      }
      this.hp = this.allHp;
    }
  }, {
    key: "play",
    value: function play() {
      var _this16 = this;
      for (var _e4 = 0; _e4 < $2DataManager.default.instance.row; _e4++) {
        $2ZombieMgr.default.instance().zombieInRow[_e4].add(this);
      }
      $2ZombieMgr.default.instance().zombieSet.add(this);
      $2ZombieMgr.default.instance().zombieNums++;
      this.scheduleOnce(function () {
        _this16.attack();
      }, 10);
    }
  }, {
    key: "hp",
    get() {
      return this._hp;
    },
    set(e) {
      this._hp = e;
    }
  }, {
    key: "hurt",
    value: function hurt(e) {
      if (0 != $2DataManager.default.instance.level && 0 != this.hp && (this.hp -= e, $2SceneStage.default.instance.showBossHp(), this.hp <= 0)) {
        this.hp = 0;
        this.unscheduleAllCallbacks();
        $2ZombieMgr.default.instance().zombieNums--;
        $2ZombieMgr.default.instance().zombieSet.delete(this);
        this.playAnimation("2baozha", false);
        var _e5 = babel_toConsumableArray($2ZombieMgr.default.instance().zombieSet.values()).length;
        for (var _t4 = 0; _t4 < _e5; _t4++) {
          babel_toConsumableArray($2ZombieMgr.default.instance().zombieSet.values())[_t4] && babel_toConsumableArray($2ZombieMgr.default.instance().zombieSet.values())[_t4].hurt(9999);
        }
        $2ZombieMgr.default.instance().stop();
        this.node.getComponent(sp.Skeleton).setCompleteListener(function () {
          $2SceneStage.default.instance.win();
        });
      }
    }
  }, {
    key: "attack",
    value: function attack() {
      var _this17 = this;
      if (3 == this.index) {
        this.scheduleOnce(function () {
          _this17.skillFire();
        }, this.cd);
      } else {
        this.scheduleOnce(function () {
          _this17.skillZhaohuan();
        }, this.cd);
      }
      this.index++;
      this.index = this.index % 4;
    }
  }, {
    key: "skillFire",
    value: function skillFire(e) {
      var _this18 = this;
      this.back();
      this.node.getComponent(sp.Skeleton).setCompleteListener(function () {
        var t = $2MyUtils.MyUtils.getRandomInt(0, 4);
        _this18.node.y = _this18.firePos[t];
        _this18.node.getComponent(sp.Skeleton).setCompleteListener(function () {
          _this18.attackDaiji();
          _this18.clearAniEvent();
          _this18.scheduleOnce(function () {
            _this18.node.getComponent(sp.Skeleton).setCompleteListener(function () {
              _this18.clearAniEvent();
              _this18.attackDaiji();
              _this18.scheduleOnce(function () {
                _this18.node.getComponent(sp.Skeleton).setCompleteListener(function () {
                  _this18.node.y = _this18.normalPos;
                  _this18.node.getComponent(sp.Skeleton).setCompleteListener(function () {
                    _this18.clearAniEvent();
                    _this18.daiji();
                  });
                  _this18.forward();
                });
                _this18.up();
              }, 8);
            });
            _this18.scheduleOnce(function () {
              for (var _a4 = 0; _a4 < $2DataManager.default.instance.row; _a4++) {
                for (var _n6 = 0; _n6 < $2DataManager.default.instance.col; _n6++) {
                  var _i4 = $2DataManager.default.instance.blockArr[_a4][_n6][1];
                  _i4 && _i4.getComponent($2PlantBase.default) && (_i4.getComponent($2PlantBase.default).row == t || _i4.getComponent($2PlantBase.default).row == t + 1 || e) && _i4.getComponent($2PlantBase.default).hurt(500);
                }
              }
            }, .5);
            _this18.fire();
          }, 8);
        });
        _this18.down();
      });
    }
  }, {
    key: "skillZhaohuan",
    value: function skillZhaohuan() {
      var _this19 = this;
      var e = $2MyUtils.MyUtils.getRandomInt(1, 6);
      this.zhaohuan(6 - e);
      this.scheduleOnce(function () {
        var t = cc.v2(300, $2DataManager.default.instance.groudYArr[e - 1]);
        $2ZombieMgr.default.instance().showItem(_this19.zombieID, t, e - 1);
      }, .5);
      this.node.getComponent(sp.Skeleton).setCompleteListener(function () {
        _this19.clearAniEvent();
        _this19.daiji();
      });
    }
  }, {
    key: "clearAniEvent",
    value: function clearAniEvent() {
      this.node.getComponent(sp.Skeleton).setCompleteListener(null);
    }
  }, {
    key: "zhaohuan",
    value: function zhaohuan(e) {
      this.playAnimation(this.aniName["zhaohuan" + e]);
    }
  }, {
    key: "back",
    value: function back() {
      this.playAnimation(this.aniName.back);
    }
  }, {
    key: "forward",
    value: function forward() {
      this.playAnimation(this.aniName.forward);
    }
  }, {
    key: "up",
    value: function up() {
      this.playAnimation(this.aniName.up);
    }
  }, {
    key: "down",
    value: function down() {
      this.playAnimation(this.aniName.down);
    }
  }, {
    key: "daiji",
    value: function daiji() {
      this.node.getComponent(sp.Skeleton).setAnimation(0, this.aniName.daiji, true);
      0 != $2DataManager.default.instance.level && this.attack();
    }
  }, {
    key: "attackDaiji",
    value: function attackDaiji() {
      this.node.getComponent(sp.Skeleton).setAnimation(0, this.aniName.attackDaiji2, true);
    }
  }, {
    key: "fire",
    value: function fire() {
      this.node.getComponent(sp.Skeleton).setAnimation(0, this.aniName.skillFire, false);
    }
  }, {
    key: "playAnimation",
    value: function playAnimation(e) {
      var t = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
      this.node.getComponent(sp.Skeleton).setAnimation(0, e, t);
    }
  }], [{
    key: "instance",
    get() {
      return this._instance;
    }
  }]);
  return n;
}($2StateComponent.default);
def_Boss._instance = null;
def_Boss = _n4 = cc__decorate([ccp_ccclass], def_Boss);
exports.default = def_Boss;